package com.winterchen.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @className TopicRabbitConfig
 * @Description     topic 是RabbitMQ中最灵活的一种方式，可以根据routing_key自由的绑定不同的队列
 *                  首先对topic规则配置，这里使用两个队列来测试
 *                  注意这里Queue的包不要导错了
 *                  使用queueMessages同时匹配两个队列，
 *                  queueMessage只匹配"topic.message"队列
 *
 *
 * @Author 张峻豪
 * @Date 2018/9/26 0026 11:04
 * @Version 1.0
 **/
@Configuration
public class TopicRabbitConfig {
    final static String message = "topic.message";
    final static String messages = "topic.messages";

    @Bean
    public Queue queueMessage() {
        return new Queue(TopicRabbitConfig.message);
    }

    @Bean
    public Queue queueMessages() {
        return new Queue(TopicRabbitConfig.messages);
    }

    @Bean
    public TopicExchange exchange() {
        return new TopicExchange("exchange");
    }

    @Bean
    public Binding bindingExchangeMessage(Queue queueMessage, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message");
    }

    //*表示一个词.
    //#表示零个或多个词.
    @Bean
    public Binding bindingExchangeMessages(Queue queueMessages, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessages).to(exchange).with("topic.#");
    }

}
